// src/food.c

#include <stdlib.h>
#include "utils.h"
#include "food.h"
#include "snake.h"

// 初始化食物
void initFood(Food* food, Snake* snake) {
    int collision;
    do {
        collision = 0;
        food->position.x = rand() % (GAME_WIDTH - 2) + 1;
        food->position.y = rand() % (GAME_HEIGHT - 2) + 1;

        for (int i = 0; i < snake->length; i++) {
            if (snake->body[i].x == food->position.x && snake->body[i].y == food->position.y) {
                collision = 1;
                break;
            }
        }
    } while (collision);
}

// 检查食物是否被吃
int isFoodEaten(Food* food, Snake* snake) {
    if (snake->body[0].x == food->position.x && snake->body[0].y == food->position.y) {
        return 1;
    }
    return 0;
}
